package com.hjh.netty.elect.demo5.handler;

import com.hjh.netty.elect.config.SpringUtils;
import com.hjh.netty.elect.demo5.bean.Pmc350DevBean;
import com.hjh.netty.elect.demo5.bean.Pmc350DevPackage;
import com.hjh.netty.elect.demo5.parser.impl.PayLoadParserImpl;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

/**
 * 010：表示终端的主动上送报文，不需要主站回复
 *
 *
 * 终端数据主动上送包括定时数据上送、事件数据上送及记录数据上送三种类型
 *
 * @author 程就人生
 * @date 2020年8月6日
 * @Description
 */
@Slf4j
public class Pmc350DevHandler010  extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        // 判断消息实例
        if (null == msg || !(msg instanceof Pmc350DevPackage)) {
            ctx.fireChannelRead(msg);
            return;
        }
        Pmc350DevPackage pmc350DevPackage  = (Pmc350DevPackage) msg;
        if(pmc350DevPackage.getPackageType() != 2){
            ctx.fireChannelRead(msg);
            return;
        }

        log.info("010：表示终端的主动上送报文，不需要主站回复|{}",pmc350DevPackage);

        //解析报文
        PayLoadParserImpl parser010 = SpringUtils.getBean(PayLoadParserImpl.class);
        Pmc350DevBean pmc350DevBean = parser010.parserPayLoad(pmc350DevPackage);
        log.info("channelRead|result:{}",pmc350DevBean);

        //把数据发送到Mq
        ctx.flush();
    }
}